有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何正确组合@PathParams和@RequestBody?

在我的Spring MVC控制器中,我试图将输入参数映射到一个对象。我的控制器目前看起来是这样的:

@RestController("fundsConfirmationController")
@RequestMapping("/accounts/{accountId}/funds-confirmations")
public class FundsConfirmationController {

@GetMapping(
        consumes = MediaType.APPLICATION_JSON_VALUE,
        produces = MediaType.APPLICATION_JSON_VALUE
)
public ResponseEntity<?> fundsConfirmation(@PathVariable("accountId") String accountId,
                                           @RequestBody FundsConfirmationRequestDTO fundsConfirmationRequestDTO) {

    System.out.println(accountId + " " + fundsConfirmationRequestDTO);

    return null;
}

因此,除了在方法中单独设置accountId之外,我还没有找到一种方法来正确组合@PathVariable@RequestBody?(我无法更改传入参数,因为这些是预定义的要求。)

在同一个对象中是否有合适的方式组合@PathParams@ResponseBody?不单独映射DTO中的路径参数

有什么建议可以妥善解决这个问题吗

如果我在错误的地方发帖,或者我需要详细说明,请纠正我

提前谢谢你,汤姆


共 (1) 个答案